﻿using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Wala.Infrastructure;

namespace Wala.Connection.Objects.Timeline
{
    public class FeedData
    {
        public List<FeedInfo> Feed;

        public FeedData()
        {
            Feed = new List<FeedInfo>();
        }

        public FeedData(List<FeedInfo> feed)
        {
            this.Feed = feed;
        }

        public List<FeedInfo> GetFeed()
        {
            List<FeedInfo> temp = new List<FeedInfo>();

            foreach (FeedInfo feedInfo in Feed)
            {
                switch (feedInfo.Type)
                {
                    case URLConstant.TargetType.PHOTO:
                    case URLConstant.TargetType.STATUS:
                        temp.Add(feedInfo);
                        break;
                    default:
                        break;
                }
            }
            return temp;
        }

        public void SetFeed(List<FeedInfo> feed)
        {
            this.Feed = feed;
        }

        public static FeedData FromJson(string json)
        {
            try
            {
                FeedData deserializedFeed = JsonConvert.DeserializeObject<FeedData>(json);
                List<FeedInfo> lstFeed = deserializedFeed.Feed;
                return new FeedData(lstFeed);
            }
            catch
            {
                return new FeedData();
            }
        }
    }
}
